import * as util from '../../../utils/util';
const app = getApp();
let that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movie:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    const movieId = options.id;
    const detailUrl=app.globalData.g_doubanBase+"/v2/movie/subject/"+movieId;
  
    util.http(detailUrl,that.processDoubanData);
  
  },

  processDoubanData:(data)=>{
    const director ={
      avatar:"",
      name:'',
      id:""
    }
    if(data.directors[0]!=null){
      if(data.directors[0].avatars!=null){
        director.avatar = data.directors[0].avatars.large;
      }
      director.name=data.directors[0].name;
      director.id=data.directors[0].id;
    }
    
    const movie = {
      movieImg: data.images?data.images.large:"",
      country:data.countries[0],
      title:data.title,
      originalTitle:data.original_title,
      wishCount:data.wish_count,
      commentCount:data.comments_count,
      year:data.year,
      generes:data.genres.join("、"),
      stars:util.convertToStarsArray(data.rating.stars),
      score:data.rating.average,
      director:director,
      casts:util.convertToCastString(data.casts),
      castsInfo:util.convertToCastInfos(data.casts),
      summary:data.summary,
    }

    that.setData({
      movie:movie
    })
  },


  //查看图片
  viewMoviePostImg:(event)=>{
    const src = event.currentTarget.dataset.src;
    wx.previewImage({
      // current: 'String', // 当前显示图片的链接，不填则默认为 urls 的第一张
      current:src,
      urls: [src],
      success: function(res){
        // success
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },

})